package com.mdt.doforms.bienen.mapnlocation;

import com.google.android.gms.maps.model.LatLng;
import com.mdt.doforms.bienen.util.HtdLog;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class MyLocation implements LocationListener {
	
	private LatLng m_currentLocation = null;
	private Context context = null;
	
	public MyLocation ( Context context){
		this.context = context;
		LocationManager mlocManager = (LocationManager)this.context.getSystemService(Context.LOCATION_SERVICE);
		mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 5000, 100, this);
	}
	
	@Override
	public void onLocationChanged(Location location) {
		// Getting latitude of the current location
		double latitude = location.getLatitude();
		// Getting longitude of the current location
		double longitude = location.getLongitude();		
//		// Creating a LatLng object for the current location
		setCurrentLocation(new LatLng(latitude, longitude));
		String Text = "My current location is: " +
				"Latitud = " + latitude +
				"Longitud = " + longitude;
		
		HtdLog.i(Text);
	}

	@Override
	public void onProviderDisabled(String provider) {

	}

	@Override
	public void onProviderEnabled(String provider) {
	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
	}
	
	public static float getDistance( LatLng src, LatLng dst ){
		float[] results = new float[1];
		Location.distanceBetween(src.latitude, src.longitude,
				dst.latitude, dst.longitude, results);
		
		return results[0];
	}

	public LatLng getCurrentLocation() {
		return m_currentLocation;
	}

	private void setCurrentLocation(LatLng m_currentLocation) {
		this.m_currentLocation = m_currentLocation;
	}
}
